//
//  AddressTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/16.
//

#import "AddressTableViewCell.h"

@implementation AddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)creatView{
    self.backgroundColor=[UIColor whiteColor];
    
    UIView *topView=[UIView new];
    [self.contentView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(126*_mainHeight);
    }];
    
    UITextField *text=[UITextField new];
    [topView addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(52*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text.text=self.nameStr;
    text.textColor=rgba(45,45,45,1);
    text.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text.textAlignment=NSTextAlignmentLeft;
    text.delegate=self;
    text.tag=1;
    text.placeholder=@"请输入真实姓名";
    text.returnKeyType=UIReturnKeyDone;
    
    UIView *leftView=[UIView new];
    [leftView setFrame:CGRectMake(0, 0, 68*_mainWidth, 60*_mainHeight)];
    UIImageView *phoneImageView=[UIImageView new];
    [leftView addSubview:phoneImageView];
    [phoneImageView setFrame:CGRectMake(0, (60*_mainHeight-28*_mainWidth)/2, 28*_mainWidth, 28*_mainWidth)];
    phoneImageView.image=[UIImage imageNamed:@"xingming"];
    text.leftView = leftView;
    text.leftViewMode =UITextFieldViewModeAlways;
    
    UIView *xianView=[UIView new];
    [self.contentView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
    
    
    UIView *topView2=[UIView new];
    [self.contentView addSubview:topView2];
    [topView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
        make.height.mas_equalTo(116*_mainHeight);
    }];
    
    UITextField *text2=[UITextField new];
    [topView2 addSubview:text2];
    [text2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(52*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text2.text=self.phoneStr;
    text2.textColor=rgba(45,45,45,1);
    text2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text2.textAlignment=NSTextAlignmentLeft;
    text2.delegate=self;
    text2.tag=2;
    text2.placeholder=@"请输入手机号";
    text2.returnKeyType=UIReturnKeyDone;

    UIView *leftView2=[UIView new];
    
    [leftView2 setFrame:CGRectMake(0, 0, 68*_mainWidth, 60*_mainHeight)];
    
    UIImageView *phoneImageView2=[UIImageView new];
    [leftView2 addSubview:phoneImageView2];
    [phoneImageView2 setFrame:CGRectMake(0, (60*_mainHeight-30*_mainWidth)/2, 30*_mainWidth, 30*_mainWidth)];
    phoneImageView2.image=[UIImage imageNamed:@"dianhua"];
    text2.leftView = leftView2;
    text2.leftViewMode =UITextFieldViewModeAlways;
    
    UIView *xianView2=[UIView new];
    [self.contentView addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView2.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView2.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView3=[UIView new];
    [self.contentView addSubview:topView3];
    [topView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView2.mas_bottom);
        make.height.mas_equalTo(116*_mainHeight);
    }];
    
    UITextField *text3=[UITextField new];
    [topView3 addSubview:text3];
    [text3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(52*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-50*_mainWidth);
        make.height.mas_equalTo(80*_mainHeight);
    }];
    text3.text=self.cityStr;
    text3.textColor=rgba(45,45,45,1);
    text3.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text3.textAlignment=NSTextAlignmentLeft;
    text3.delegate=self;
    text3.tag=3;
    text3.placeholder=@"选择寄件城市/区域";
    text3.enabled=NO;
    text3.returnKeyType=UIReturnKeyDone;
    
    UIView *leftView3=[UIView new];
    [leftView3 setFrame:CGRectMake(0, 0, 68*_mainWidth, 60*_mainHeight)];
    UIImageView *phoneImageView3=[UIImageView new];
    [leftView3 addSubview:phoneImageView3];
    [phoneImageView3 setFrame:CGRectMake(0, (60*_mainHeight-36*_mainWidth)/2, 27*_mainWidth, 36*_mainWidth)];
    phoneImageView3.image=[UIImage imageNamed:@"dingwei"];
    text3.leftView = leftView3;
    text3.leftViewMode =UITextFieldViewModeAlways;
    
    UIView *rightView3=[UIView new];
    [rightView3 setFrame:CGRectMake(0, 0, 68*_mainWidth, 60*_mainHeight)];
    UIButton *ImageView3=[UIButton new];
    [rightView3 addSubview:ImageView3];
    [ImageView3 setFrame:CGRectMake(68*_mainWidth-11*_mainWidth, (60*_mainHeight-24*_mainWidth)/2, 11*_mainWidth, 24*_mainWidth)];
    [ImageView3 setImage:[UIImage imageNamed:@"gengduo"] forState:0];
    text3.rightView = rightView3;
    text3.rightViewMode =UITextFieldViewModeAlways;
    
    topView3.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(slectCityBtn:)];
    [topView3 addGestureRecognizer:tapGesture];
    
    UIView *xianView3=[UIView new];
    [self.contentView addSubview:xianView3];
    [xianView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_mainWidth*17);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(topView3.mas_bottom);
        make.height.mas_equalTo(1*_mainHeight);
    }];
    xianView3.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView4=[UIView new];
    [self.contentView addSubview:topView4];
    [topView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(xianView3.mas_bottom);
        make.height.mas_equalTo(226*_mainHeight);
    }];
    topView4.userInteractionEnabled=YES;
    
    UIImageView *iamgeView=[UIImageView new];
    [topView4 addSubview:iamgeView];
    [iamgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(text);
        make.top.mas_equalTo(46*_mainHeight);
        make.width.mas_equalTo(30*_mainWidth);
        make.height.mas_equalTo(26*_mainWidth);
    }];
    iamgeView.image=[UIImage imageNamed:@"xiangxidizhi"];
    
    UITextView *text4=[UITextView new];
    [topView4 addSubview:text4];
    [text4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(94*_mainWidth);
        make.top.mas_equalTo(34*_mainHeight);
        make.height.mas_equalTo(192*_mainHeight);
        make.right.mas_equalTo(-50*_mainWidth);
    }];
    text4.tag=4;
    text4.backgroundColor=rgba(248,248,247,1);
    text4.layer.masksToBounds=YES;
    text4.layer.cornerRadius=25*_mainHeight;
    if (self.detailedStr==nil) {
        text4.text=@"填写详细单元楼，门牌号";
        text4.textColor=rgba(196,196,198,1);
    }else{
        text4.text=self.detailedStr;
        text4.textColor=rgba(45,45,45,1);
    }
    text4.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(34)];
    text4.delegate=self;
    text4.returnKeyType=UIReturnKeyDone;
    
    UIView *bottomView=[UIView new];
    [self.contentView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(topView4.mas_bottom);
    }];
    
    UIButton *agreementBtn=[UIButton new];
    [bottomView addSubview:agreementBtn];
    [agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(52*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(18*_mainWidth);
    }];
    if (self.isAgreement) {
        [agreementBtn setImage:[UIImage imageNamed:@"xuanzhong"] forState:0];
    }else{
        [agreementBtn setImage:[UIImage imageNamed:@"weixuanzhong"] forState:0];
    }
    [agreementBtn addTarget:self action:@selector(selectAgreementBtn) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *label=[UILabel new];
    [bottomView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(73*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(36*_mainHeight);
    }];
    label.text=@"设为默认寄件地址";
    label.textColor=rgba(144,149,165,1);
    label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    label.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAgreementBtn)];
    [label addGestureRecognizer:tapGesture2];
    
    UIButton *deleteBtn=[UIButton new];
    [bottomView addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(170*_mainWidth);
        make.height.mas_equalTo(50*_mainHeight);
    }];
    [deleteBtn setTitle:@"清空当前信息" forState:0];
    [deleteBtn setTitleColor:rgba(144,149,165,1) forState:0];
    deleteBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    deleteBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    [deleteBtn addTarget:self action:@selector(selectEmptyBtn) forControlEvents:UIControlEventTouchUpInside];
}

-(void)creatBtnView{
    self.backgroundColor=[UIColor clearColor];
    
    UIButton *signInBtn=[UIButton new];
    [self.contentView addSubview:signInBtn];
    [signInBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(39*_mainWidth);
        make.width.mas_equalTo(_mainW-78*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(_mainHeight*87);
    }];
    [signInBtn setTitle:@"确定" forState:0];
    [signInBtn setTitleColor:[UIColor whiteColor] forState:0];
    signInBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    
    [signInBtn layoutIfNeeded];
    signInBtn.layer.masksToBounds=YES;
    signInBtn.layer.cornerRadius=87*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = signInBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [signInBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    signInBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    signInBtn.layer.shadowOffset = CGSizeMake(0,0);
    signInBtn.layer.shadowOpacity = 1;
    signInBtn.layer.shadowRadius = 4;
    [signInBtn addTarget:self action:@selector(selectSubmitBtn:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    textView.textColor=rgba(45, 45, 45, 1);
    NSString *textStr=textView.text;
    if ([textStr isEqual:@"填写详细单元楼，门牌号"]) {
        textView.text=@"";
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    NSString *textStr=textView.text;
    if ([ZQTools charIsNil:textStr]) {
        textView.text=@"填写详细单元楼，门牌号";
        textView.textColor=rgba(248,248,247, 1);
    }else{
        if (self.delegate!=nil) {
            [self.delegate textViewdDidEnd:textView];
        }
    }
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.delegate!=nil) {
        [self.delegate textFiledDidEnd:textField];
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([text isEqualToString:@"\n"]){
        [textView resignFirstResponder];
        return NO;
    }
    return YES;

}
-(void)selectAgreementBtn{
    if (self.delegate!=nil) {
        [self.delegate selectAgreement];
    }
}
-(void)selectEmptyBtn{
    if (self.delegate!=nil) {
        [self.delegate selectEmpty];
    }
}
-(void)slectCityBtn:(UITapGestureRecognizer *)tap{
    
}
-(void)selectSubmitBtn:(UIButton *)btn{
    if (self.delegate!=nil) {
        [self.delegate selectSubmit];
    }
}


@end
